// views/index/shop/translationcopy/ordermessage/index.js
var util = require('../../../../../../utils/util');
var area = require('../../../../../../utils/area');

var BASE_URL = getApp().globalData.BASE_URL
import Notify from '../../../../../../miniprogram_npm/@vant/weapp/notify/notify';
import Dialog from '../../../../../../miniprogram_npm/@vant/weapp/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    columns: ['Aachen', 'Aalen', 'Augsburg', 'Baden', 'Bad Soden-Salmuenster', 'Bamberg', 'Bayreuth', 'Berlin', 'Bernburg', 'Biberach', 'Bielefeld', 'Birkenfeld', 'Bochum', 'Bonn', 'Braunschweig', 'Bremen', 'Chemnitz', 'Clausthal-Zellerfeld', 'Coburg', 'Cottbus', 'Darmstadt', 'Dessau', 'Dortmund', 'Dresden', 'Duesseldorf', 'Duisburg', 'Eichstätt', 'Erfurt', 'Erlangen', 'Essen', 'Frankfurt am Main', 'Frankfurt an der Oder', 'Freiberg', 'Freiburg', 'Friedrichshafen', 'Fulda', 'Furtwangen', 'Garching', 'Garmisch-Partenkirchen', 'Gatersleben', 'Geesthacht', 'Germersheim', 'Giessen', 'Goettingen', 'Greifswald', 'Hagen', 'Halle', 'Hamburg', 'Hannover', 'Heide', 'Heidelberg', 'Heidenheim', 'Hof', 'Hohenheim', 'Holzkirchen', 'Homburg', 'Ilmenau', 'Ingolstadt', 'Jena', 'Juelich', 'Kaiserslautern', 'Karlsruhe', 'Kassel', 'Kiel', 'Kleve', 'Koblenz', 'Koeln', 'Koethen', 'Konstanz', 'Landshut', 'Leipzig', 'Lindau', 'Ludwigshafen', 'Luebeck', 'Lueneburg', 'Magdeburg', 'Mainz', 'Mannheim', 'Marbach am Neckar', 'Marburg', 'Mildesheim', 'Mittweida', 'Monchengladbach', 'Muelheim an der Ruhr', 'Muenchen', 'Muenster', 'Neuss', 'Nordhausen', 'Nuernberg', 'oestrich-Winkel', 'Offenbach', 'Offenburg', 'Oldenburg', 'Osnabrueck', 'Paderborn', 'Passau', 'Pforzheim', 'Potsdam', 'Radolfzell am Bodensee', 'Ravensburg', 'Reutlingen', 'Rostock', 'Saarbruecken', 'Schmakalden', 'Schweinfurt', 'Schwerin', 'Senftenberg', 'Siegen', 'Stralsund', 'Stuttgart', 'Trier', 'Tuebingen', 'Ulm', 'Vallendar', 'Vechta', 'Villingen', 'Weimar', 'Weingarten in baden-Wuerttemberg', 'Weinheim', 'Wernigerode', 'Wessling', 'Wiesbaden', 'Wismar', 'Worms', 'Wuerzburg', 'Wuppertal', 'Zwickau', 'Other'],
    xueqishu: ['2018WS', '2019SS', '2019WS', '2020SS', '2020WS', '2021SS', '2021WS', '2022SS', '2022WS', '2023SS', '2023WS'],
    minDate: new Date(1950, 0, 1).getTime(),
    opendiqupop: false,
    showdatepop: false,
    openxueqipop: false,
    currentDate: new Date().getTime(),
    nowtime: "",
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      }
      if (type === 'month') {
        return `${value}月`;
      }
      return value;
    },

    time_type: "",

    yuji_city: "",
    rude: "",
    jiudu: "",
    fangxiang: "",
    school: "",
    xueqi: "2020WS",
    zongji: "",
    qixian: "半年内",
    ifswitch: false,
    needs: 0,
    bao_name: "",
    bao_company: "",
    bao_start: "",
    bao_end: "",
    email: "",
    beizhu: "",
    price: "",





    //第二页数据
    tel: "",
    wechat: "",
    contact_per: "",
    contact_tel: "",
    shifou: 0,
    shou_per: "",
    loca: "",
    yb: 0,
    city: 'Aachen',

    //第一页数据
    name: '',
    x_spell: '',
    m_spell: '',
    sex: '',
    birth: '',
    born: '',
    marriage: '',
    country: '',
    passport: '',
    or_bank: '',
    bank_hu: '',
    bank_bic: '',
    bank_ren: '',


  },


  change_switch: function (e) {
    console.log(e)
    this.setData({
      ifswitch: e.detail
    })
  },

  //确定时间
  change_date: function () {


    if (this.data.time_type == 'jointime') {
      this.setData({
        rude: this.changeTime(this.data.nowtime),
      })
    }
    if (this.data.time_type == 'baostarttime') {
      this.setData({
        bao_start: this.changeTime(this.data.nowtime),
      })
    }
    if (this.data.time_type == 'baoendtime') {
      this.setData({
        bao_end: this.changeTime(this.data.nowtime),
      })
    }
    this.setData({
      showdatepop: false,
      currentDate: new Date().getTime(),
    })
  },
  //切换时间
  getColumnValue(event) {
    console.log(event)
    this.setData({
      nowtime: event.detail,
    });
  },

  //打开时间pop
  opendatepop: function (e) {
    this.setData({
      showdatepop: true,
      time_type: e.currentTarget.dataset.type
    })
  },

  //关闭时间pop
  onClose: function () {
    this.setData({
      showdatepop: false,
      opendiqupop: false,
      openxueqipop: false,
      currentDate: new Date().getTime(),
    })
  },
  //打开地区选择遮罩层
  open_area: function (e) {
    this.setData({
      opendiqupop: true
    })
  },
  open_xueqi: function (e) {
    this.setData({
      openxueqipop: true,
    })
  },

  //领域切换
  change_qixian: function (e) {
    this.setData({
      qixian: e.currentTarget.dataset.qixian
    })
  },

  //确定城市
  onConfirm: function (e) {
    this.setData({
      opendiqupop: false,
      yuji_city: e.detail.value
    })
  },
  onConfirm_xueqi: function (e) {
    this.setData({
      openxueqipop: false,
      xueqi: e.detail.value
    })
  },






  //立即办理
  placeorder: function () {
    var _this = this
    var userinfo = wx.getStorageSync("USER")
    if (_this.data.yuji_city == "") {
      Notify('预计到达城市不能为空');
    }
    if (_this.data.rude == "") {
      Notify('预计入境德国时间不能为空');
    }
    if (_this.data.jiudu == "") {
      Notify('学校名称不能为空');
    }
    if (_this.data.fangxiang == "") {
      Notify('专业方向不能为空');
    }
    if (_this.data.school == "") {
      Notify('学校地址不能为空');
    }
    if (_this.data.xueqi == "") {
      Notify('当前报名学期不能为空');
    }
    if (_this.data.zongji == "") {
      Notify('总计攻读学期数不能为空');
    }
    if (_this.data.yuji_city !== "" && _this.data.rude !== "" && _this.data.jiudu !== "" && _this.data.fangxiang !== "" && _this.data.school !== "" && _this.data.xueqi !== "" && _this.data.zongji !== "") {
      wx.request({
        url: `${BASE_URL}/baoxian/gonglidata`,
        method: "POST",
        data: {
          yuji_city: _this.data.yuji_city,
          rude: _this.data.rude,
          jiudu: _this.data.jiudu,
          fangxiang: _this.data.fangxiang,
          school: _this.data.school,
          xueqi: _this.data.xueqi,
          zongji: _this.data.zongji,
          qixian: _this.data.qixian,
          needs: _this.data.ifswitch ? '是' : '否',
          bao_name: _this.data.bao_name,
          bao_company: _this.data.bao_company,
          bao_start: _this.data.bao_start,
          bao_end: _this.data.bao_end,
          email: _this.data.email,
          beizhu: _this.data.beizhu,
          uid: userinfo.id,
          type: 'xiaochengxv',
          id: _this.data.id,



          //第二页数据
          tel: _this.data.tel,
          wechat: _this.data.wechat,
          contact_per: _this.data.contact_per,
          contact_tel: _this.data.contact_tel,
          shifou: _this.data.shifou,
          shou_per: _this.data.shou_per,
          loca: _this.data.loca,
          yb: _this.data.yb,
          city: _this.data.city,

          //第一页数据

          name: _this.data.name,
          x_spell: _this.data.x_spell,
          m_spell: _this.data.m_spell,
          sex: _this.data.sex,
          birth: _this.data.birth,
          born: _this.data.born,
          marriage: _this.data.marriage,
          country: _this.data.country,
          passport: _this.data.passport,
          or_bank: _this.data.or_bank,
          bank_hu: _this.data.bank_hu,
          bank_bic: _this.data.bank_bic,
          bank_ren: _this.data.bank_ren,



        },
        header: {
          'Content-Type': 'application/json' //GET方式是这个
        },
        success(res) {
          console.log(res)
          wx.navigateTo({
            url: `../sureorder/index?id=${res.data.id}`
          })
        }
      })

    }
  },







  getdatalist: function () {
    var _this = this
    var userinfo = wx.getStorageSync("USER")
    wx.request({
      url: `${BASE_URL}/baoxian/gonglidata`, //仅为示例，并非真实的接口地址
      data: {
        id: _this.data.id,
        type: 'xiaochengxv',
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      method: "get",
      success(res) {
        console.log(res)
        if (res.data.list.info) {
          res.data.list.info = JSON.parse(res.data.list.info)
        }
        if (res.data.list.xinxi) {
          res.data.list.xinxi = JSON.parse(res.data.list.xinxi)
        }
        _this.setData({
          price: res.data.list.amount,

          //第一页

          name: res.data.list.name,
          x_spell: res.data.list.x_spell,
          m_spell: res.data.list.m_spell,
          sex: res.data.list.sex,
          birth: res.data.list.birth,
          born: res.data.list.born,
          marriage: res.data.list.marriage,
          country: res.data.list.country,
          passport: res.data.list.passport,
          or_bank: res.data.list.bank,
          bank_hu: res.data.list.info.bank_hu,
          bank_bic: res.data.list.info.bank_bic,
          bank_ren: res.data.list.info.bank_ren,


          //第二页
          tel: res.data.list.tel,
          wechat: res.data.list.wechat,
          contact_per: res.data.list.contact_per,
          contact_tel: res.data.list.contact_tel,
          shifou: res.data.list.info.shifou,
          shou_per: res.data.list.shou_per,
          loca: res.data.list.loca,
          yb: res.data.list.yb,
          city: res.data.list.city,

        })
      }
    })
  },










  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.id,
      // id: 1427
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getdatalist()

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var userinfo = wx.getStorageSync("USER")
    this.setData({
      email: userinfo.email
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  //手机号正则
  codeVerification: function (phone) {
    let phoneCodeVerification = /^[1][3,4,5,7,8][0-9]{9}$/;
    return phoneCodeVerification.test(phone);
  },
  //英文字母正则
  ifenglish: function (pinyin) {
    let ifenglish = /^[A-Za-z]+$/;
    return ifenglish.test(pinyin);
  },
  //汉字正则
  ifhanzi: function (pinyin) {
    let ifhanzi = /^[\u4e00-\u9fa5]+$/;
    return ifhanzi.test(pinyin);
  },
  //微信号正则
  ifwewhat: function (pinyin) {
    let ifwewhat = /^[0-9a-zA-Z]*$/g;
    return ifwewhat.test(pinyin);
  },
  //邮箱验证
  ifemail: function (email) {
    let ifemail = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    return ifemail.test(email);
  },









  // 时间戳转换
  changeTime(time) {
    if (time) {
      var oDate = new Date(time * 1),
        oYear = oDate.getFullYear(),
        oMonth = oDate.getMonth() + 1,
        oDay = oDate.getDate(),
        oTime = oYear + "/" + this.getBz(oMonth) + "/" + this.getBz(oDay)
      return oTime;
    } else {
      return "";
    }
  },
  // 补0
  getBz(num) {
    if (parseInt(num) < 10) {
      num = "0" + num;
    }
    return num;
  },


})